<template>
    <div>
        <ul>
            <li v-for="i in goods">
                {{i.name}} &ensp;&ensp;&ensp;&ensp;{{i.dcount}}&ensp;&ensp;&ensp;&ensp;{{i.dcontent}}&ensp;&ensp;&ensp;&ensp;{{i.dprice}}
                <button @click="buy(i.id)">购买</button>
            </li>
        </ul>
    </div>
</template>

<script>
    export default {
        data() {
            return {
                goods:[],
                userid:localStorage.getItem('userid')
            }
        },
        methods: {
            getgoods(){
                this.$axios.get('/getgoods/').then(res=>{
                    this.goods = res.data.list
                })
            },
            //购买
            buy(goodsid){
                this.$axios.get('/createorder/?userid='+this.userid+'&goodsid='+goodsid).then(res=>{
                    if(res.data.code == 200){
                        // window.location.href = res.data.url
                        this.$router.push({path:res.data.url,query:{'order_on':res.data.order_on}})
                    }
                })
            }
        },
        mounted() {
            this.getgoods()
        },
    }
</script>

<style scoped>

</style>